﻿@using VirtualPress.Infrastructure.Entities.Entity;
@using VirtualPress.Tool.Framework;
@using VirtualPress.Infrastructure.Entities.Enum;
@using VirtualPress.Infrastructure.Entities.JSONModel;
@{
    Article article = ViewBag.Article;
    ViewBag.Title = "稿件详情 -- " + article.Title;
    Layout = "/Areas/WorkSpace/Views/Shared/_WorkSpace.cshtml";
}
@{List<AuditingRecord> record = ViewBag.AuditingRecord;
  Meeting meeting = ViewBag.Meeting;
  List<ArticleAuthor> author = ViewBag.ArticleAuthor;
  List<Appendix> Attachment = ViewBag.Attachment;}
@section head
  {
    <style type="text/css">
        .attachment
        {
        }
        .filelink
        {
            margin-left: 10px;
            width: 45%;
            display: block;
            float: left;
        }
        .type
        {
            width: 100px;
            color: Gray;
            text-align: center;
            display: block;
            float: left;
        }
        .italic
        {
            color: Gray;
            font-style: italic;
        }
        hr
        {
            padding: 0;
            margin: 5px 0 5px 0;
            line-height: 1px;
        }
    </style>
}
<link type="text/css" rel="Stylesheet" href="/content/css/select2.css" />
<div id="content-header">
    <h1>
        稿件详情</h1>
</div>
<div id="breadcrumb">
    <a href="/WorkSpace/Member/Index" class="tip-bottom"><i class="icon-home"></i>起始页</a>
    <a class="current">稿件详情</a>
</div>
<div class="container-fluid">
    @if (record != null && record.Any() && (int)article.Status >= (int)ArticleStatus.ZhuanShen && article.Status != ArticleStatus.Close)
    {
        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title">
                        <h5>
                            专审详情</h5>
                        @if (article.Status == ArticleStatus.ZhuanShen)
                        {
                            <div class="buttons">
                                <a href="javascript:;" onclick="appendExpertOpt()" class="btn btn-success btn-mini">
                                    <i class="icon-plus icon-white"></i>添加审稿专家</a>
                            </div>
                        }
                    </div>
                    <div class="widget-content nopadding">
                        <table id="tbrecord" class="table table-bordered">
                            <thead>
                                <tr>
                                    <td>
                                        分配专家
                                    </td>
                                    <td width="10%">
                                        审核类型
                                    </td>
                                    <td width="15%">
                                        分配时间
                                    </td>
                                    <td width="15%">
                                        要求完成时间
                                    </td>
                                    <td width="12%">
                                        审核状态
                                    </td>
                                    <td width="12%">
                                        审核意见
                                    </td>
                                    <td width="15%">
                                        &nbsp;
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in record)
                                {
                                    if (item.Step == ExamineStep.ChuShen || item.Step == ExamineStep.ZhongShen)
                                    {
                                        continue;
                                    }
                                    <tr>
                                        <td>
                                            @item.ExpertRealName
                                        </td>
                                        <td>
                                            @item.Step.Mapping()
                                        </td>
                                        <td>
                                            @item.CreateTime.ToString("yyyy-MM-dd HH:mm")
                                        </td>
                                        <td>
                                            @item.ExamineFinishDate.ToString("yyyy-MM-dd")
                                        </td>
                                        <td>
                                            @if (item.ExamineStatus == ExamineStatus.DaiShenHe)
                                            {
                                                <b style="color: #f89406;">@item.ExamineStatus.Mapping()</b> 
                                            }
                                            else if (item.ExamineStatus == ExamineStatus.WanCheng)
                                            {
                                                <b style="color: #468847;">@item.ExamineStatus.Mapping()</b> 
                                            }
                                            else if (item.ExamineStatus == ExamineStatus.QuXiao || item.ExamineStatus == ExamineStatus.Decline)
                                            { 
                                                <b style="color: #999;">@item.ExamineStatus.Mapping()</b> 
                                            }
                                        </td>
                                        <td>
                                        @if (item.ExamineStatus == ExamineStatus.WanCheng)
                                        {
                                            @item.SuggestStatus.Mapping()
                                        }
                                        </td>
                                        <td>
                                            @if (item.ExamineStatus == ExamineStatus.DaiShenHe && article.Status == ArticleStatus.ZhuanShen)
                                            { 
                                                <input type="button" class="btn btn-warning btn-mini" value="催审" onclick="urgeExamine(@item.Id,this)" />
                                                <input type="button" class="btn btn-danger btn-mini" value="取消" onclick="cancelexamine(@item.Id)" />
                                            }
                                            else if (item.ExamineStatus == ExamineStatus.WanCheng)
                                            {
                                                <a href="/workspace/meeting/examineresult/@item.Id" target="_blank" class="btn btn-primary btn-mini">
                                                    查看</a>
                                            }
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                    @if (article.Status == ArticleStatus.ZhuanShen)
                    {
                        <div class="widget-content" style="text-align: center;">
                            <a href="/workspace/meeting/CheckAndAcceptance?articleId=@article.Id" class="btn btn-primary">
                                专审验收</a>
                        </div>
                    }
                </div>
            </div>
        </div>
        
        <div id="newexpertbox" class="row-fluid" style="display: none;">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title">
                        <h5>
                            添加审稿专家</h5>
                    </div>
                    <div class="widget-content nopadding">
                        <form class="form-horizontal">
                        <div class="control-group">
                            <label class="control-label">
                                选择专家</label>
                            <div class="controls">
                                <select id="sltExpert" name="expert">
                                    @{List<ExpertAndJobModel> list = ViewBag.ExpertList;
                                      if (list != null && list.Any())
                                      {
                                          foreach (var item in list)
                                          {
                                        <option value="@item.ExpertUserName">@item.ExpertName @item.JobCount</option>
                                          }
                                      }
                                    }
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                审稿完成时间 （天）:</label>
                            <div class="controls">
                                <input id="txtFinishDate" onblur="changefinishdate(this)" style="width:180px !important;" type="text" name="FinishDate" value="@meeting.DefaultExamineDay" />
                                &nbsp;&nbsp;&nbsp;于 <span id="boxfinishdate">@(DateTime.Now.AddDays(meeting.DefaultExamineDay).ToString("yyyy-MM-dd"))</span>
                                审稿完成
                            </div>
                        </div>
                        <div class="form-actions">
                            <a href="javascript:;" class="btn" onclick="cancelAddExpert(this)">取 消</a> <a href="javascript:;"
                                class="btn btn-primary" onclick="addExpert()">添 加</a>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    }
    <div class="row-fluid">
        <div class="span8">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-pencil"></i></span>
                    <h5>
                        稿件详情</h5>
                </div>
                <div class="widget-content nopadding">
                    <form class="form-horizontal" method="post" enctype="multipart/form-data" action="/WorkSpace/member/ArticleRevise">
                    <input type="hidden" name="ArticleId" value="@article.Id" />
                    <div class="step">
                        <div class="control-group">
                            <label class="control-label">
                                期刊名称</label>
                            <div class="controls">
                                <label class="controls-label">@meeting.Name</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                稿件标题</label>
                            <div class="controls">
                                <label class="controls-label">@article.Title -- <b style="color: Green;">@article.Status.Mapping()</b></label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                英文标题</label>
                            <div class="controls">
                                <label class="controls-label">@article.Title_EN</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                稿件范围</label>
                            <div class="controls">
                                <label class="controls-label">@article.GJFW.Replace(";", "、 ")</label>
                            </div>
                        </div>
                        <div id="authorbox" class="control-group">
                            <label class="control-label">
                                稿件作者</label>
                            <div class="controls">
                                <label class="controls-label">
                                    @foreach (var item in author)
                                    { 
                                        @Html.Raw(item.AuthorName + " ")
                                    }
                                </label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                摘要</label>
                            <div class="controls">
                                <p class="controls-label">@article.Abstract</p>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                关键字</label>
                            <div class="controls">
                                <label class="controls-label">@article.KeyWords</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                摘要(ENGLISH)</label>
                            <div class="controls">
                                <p class="controls-label">@article.Abstract_EN</p>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                关键字(ENGLISH)</label>
                            <div class="controls">
                                <label class="controls-label">@article.KeyWords_EN</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                稿件</label>
                            <div class="controls">
                                <div>
                                    @if (Attachment != null && Attachment.Any())
                                    {
                                        var chugao = Attachment.Where(c => c.AttachmentStatus == AttachmentStatus.ChuGao).ToList();
                                        var xiuding = Attachment.Where(c => c.AttachmentStatus == AttachmentStatus.XiuDingGao).ToList();
                                        var zhonggao = Attachment.Where(c => c.AttachmentStatus == AttachmentStatus.ZhongGao).ToList();
                                        var dinggao = Attachment.Where(c => c.AttachmentStatus == AttachmentStatus.DingGao).ToList();

                                        if (chugao.Any())
                                        {
                                            foreach (var att in chugao)
                                            {
                                        <div class="attachment">
                                            <a class="filelink" href="/download?token=@EncodeByBase64.Encode(new { id = att.Id, type = 9 }.ToJson())" title="点击下载">
                                                <i class="icon-download"></i>@att.FileName.PieceOfString(0, 15, "...")</a><span class="type">初稿</span>
                                            <span class="italic">@att.CreateTime.ToString("yyyy-MM-dd")
                                            </span>
                                            @if (!String.IsNullOrEmpty(att.Suggestion))
                                            {

                                                <a style="width:10px; margin-left:10px;" title="查看审稿详情" target="_blank" href="/workspace/console/showsuggestion/@att.Id">
                                                    <i class="icon-envelope icon-larger"></i></a>
                                            }
                                        </div>
                                            }
                                        <hr />
                                        }
                                        if (xiuding.Any())
                                        {
                                            foreach (var att in xiuding)
                                            { 
                                        <div class="attachment">
                                            <a class="filelink" target="_blank" title="点击下载" href="/download?token=@EncodeByBase64.Encode(new { id = att.Id, type = 9 }.ToJson())">
                                                <i class="icon-download"></i>@att.FileName</a><span class="type">修订稿</span><span
                                                    class="italic">@att.CreateTime.ToString("yyyy-MM-dd")</span>
                                            @if (!String.IsNullOrEmpty(att.Suggestion))
                                            {

                                                <a style="width:10px; margin-left:10px;" title="查看审稿详情" target="_blank" href="/workspace/console/showsuggestion/@att.Id">
                                                    <i class="icon-envelope icon-larger"></i></a>
                                            }
                                        </div>
                                            }
                                        <hr />
                                        }
                                        if (dinggao.Any())
                                        {
                                            foreach (var att in dinggao)
                                            {
                                        <div class="attachment">
                                            <a class="filelink" target="_blank" title="点击下载" href="/download?token=@EncodeByBase64.Encode(new { id = att.Id, type = 9 }.ToJson())">
                                                <i class="icon-download"></i>@att.FileName</a><span class="type">终稿</span><span class="italic">@att.CreateTime.ToString("yyyy-MM-dd")</span></div>
                                            }
                                        }
                                    }
                                </div>
                            </div>
                        </div>
                        @if (ViewBag.Recommendation != null)
                        {
                            <div class="control-group">
                                <label class="control-label">
                                    专家推荐材料</label>
                                <div class="controls">
                                    <div class="controls-label">
                                        <div class="attachment">
                                            <a target="_blank" title="点击下载" href="/download?token=@EncodeByBase64.Encode(new { id = ViewBag.Recommendation.Id, type = 9 }.ToJson())">
                                                <i class="icon-download"></i>@ViewBag.Recommendation.FileName </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        }
                    </div>
                    <div class="form-actions">
                        <a class="btn btn-primary" href="/workspace/meeting/article">返回</a>
                    </div>
                    <div id="submitted">
                    </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="span4">
            <div class="accordion widget-box" id="collapse-group">
                <div class="accordion-group widget-box">
                    <div class="accordion-heading">
                        <div class="widget-title">
                            <a data-parent="#collapse-group" href="#collapseGOne" data-toggle="collapse"><span
                                class="icon"><i class="icon-magnet"></i></span>
                                <h5>
                                    稿件历史记录</h5>
                            </a>
                        </div>
                    </div>
                    <div class="accordion-body collapse" id="collapseGOne">
                        <div class="widget-content">
                            <ul class="activity-list">
                                @{
                                    List<ArticleHistory> his = ViewBag.History;
                                    if (his != null && his.Any())
                                    {
                                        foreach (var item in his)
                                        {
                                    <li><a href="javascript:;"><i class="icon-chevron-right"></i><strong>@item.Message</strong>
                                        <span>@item.CreateTime.ToString("yyyy-MM-dd")</span> </a></li>
                                        }
                                    }
                                }
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="accordion-group widget-box">
                    <div class="accordion-heading">
                        <div class="widget-title">
                            <a data-parent="#collapse-group" href="#collapseGTwo" data-toggle="collapse"><span
                                class="icon"><i class="icon-magnet"></i></span>
                                <h5>
                                    审稿记录</h5>
                            </a>
                        </div>
                    </div>
                    <div class="accordion-body in collapse" id="collapseGTwo">
                        <div class="widget-content">
                            <ul class="activity-list">
                                @{
                                    if (record != null && record.Any())
                                    {
                                        foreach (var item in record)
                                        {
                                    <li><a href="javascript:;"><i class="icon-chevron-right"></i><strong>@item.Step.Mapping()</strong>
                                        @item.ExamineStatus.Mapping()
                                        <span>@item.CreateTime.ToString("yyyy-MM-dd")</span>
                                        @if (!String.IsNullOrEmpty(@item.Message))
                                        {
                                            <i style="float:right;" title="@item.Message" class="icon-comment"></i>
                                        }
                                    </a></li>
                                        }
                                    }
                                    else
                                    {
                                    <li><a href="javascript:;"><i class="icon-chevron-right"></i>暂无记录 </a></li>
                                    }
                                }
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section tail
{
    <script type="text/javascript">
        $(function () {
            $('#likarticle').addClass('active open');

            $('#finishform').submit(function(){
                var res = $('#sltres').val();
                var msg = $('#tarmsg').val();
                if(res != 0){
                    if(msg == ''){
                        $('#tarmsg').parent().parent().addClass('error');
                        $('#tarmsg').parent().children('span').remove();
                        $('#tarmsg').parent().append(
                            $('<span generated="true" class="help-inline">requird.</span>')
                        );
                        return false;
                    }
                }
            });
        });
        function cancelexamine(id) {
            if (confirm('您确认取消该专家的审稿权限吗？')) {
                window.location.href = '/workspace/meeting/cancelExamine/' + id + '?articleId=@article.Id';
            }
        }
        function urgeExamine(id,sender){
            if(confirm('是否确认向该专家发送催审通知邮件')){
                $.ajax({
                    url:'/workspace/meeting/urgeExamine/'+id,
                    success:function(){
                        $(sender).parent().html('<span class="label label-success">催审邮件已发出</span>');
                    }
            });
            }
        }
        function cancelAddExpert(sender) {
             $('#newexpertbox').hide();
        }
        function appendExpertOpt(){
            $('#newexpertbox').show();
        }
        function addExpert(){
            var expert = $('#sltExpert').val();
            var finishDate = $('#txtFinishDate');

            if (!/^\d+$/.test(finishDate.val())) {
                finishDate.parent().parent().parent().addClass('error');
                finishDate.parent().parent().append(
                            $('<span generated="true" class="help-inline">输入有误.</span>')
                        );
                return false;
            }
            $.ajax({
                url:'/workspace/meeting/appendExamineExpert',
                data:{
                    articleId:@article.Id,
                    expert:expert,
                    finishDate:finishDate.val()
                },
                type:'get',
                success:function(res){
                   window.location.href=window.location.href;
                }
            });
        }
        function changeexamineresult(sender){
            if($(sender).val() == 0) {
                $('#resmsgbox').hide();
            }
            else{
                $('#resmsgbox').show();
            }
        }
        function changefinishdate(sender) {
            var day = $(sender).val();
            if (parseInt(day, 10) > 0) {
                day = parseInt(day, 10);
                var myhelper = new dateHelper();
                var newdate = myhelper.AddDays(new Date(), day);
                $('#boxfinishdate').text(myhelper.Format(newdate, "yyyy-MM-dd"));
            }
        }
    </script>
}
